import { computed, observable } from "mobx";

class Todo {
  @observable value
  @observable id
  @observable complete

  constructor(value) {
    this.value = value;
    this.id = Date.now();
    this.complete = false;
  }
}

export class TodoStore {
  @observable todos = [];
  @observable filter = "";
  @computed get filteredTodos() {
    var matchesFilter = new RegExp(this.filter, "i");
    return this.todos.filter(todo => !this.filter || matchesFilter.test(todo.value));
  }

  createTodo(value) {
    this.todos.push(new Todo(value));
  }

  clearComplete = () => {
    this.todos = this.todos.filter(todo => !todo.complete);
  }
}
const todoStore = new TodoStore();
window.todoStore = todoStore;

export default todoStore;

